<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html>
<?php 
	session_start();
	if ( !isset($_SESSION['user']))
	{
		include_once("login.php");
		exit();
	}
?>
<head>
  <title>Traductor de fans</title>
  <link rel="stylesheet" href="css/fantrad.css">
  <link rel="stylesheet" href="css/jquery.fancybox-1.3.4.css">
  <script type="text/javascript">

	var diccionario = new Object();
	<?php
		include_once("src/BD.php");
		
		//TODO: Cachear el glosario!!!
		
		$bd = new BD;
		if ($_SESSION['doc'] )
		{
			$diccionario_bd = $bd->getDiccionario($_SESSION['doc']);
			for($i =0 ; $i<sizeof($diccionario_bd); $i++)
			{
					print ('diccionario[\''.$diccionario_bd[$i]['clave'].'\'] = \''.$diccionario_bd[$i]['valor'].'\';');
			}
		}
	?>
	diccionario['jon'] = 'nieve';
	diccionario['test'] = 'hello world';
	
	function pulsa_glosario(event)
	{
            var chCode = ('charCode' in event) ? event.charCode : event.keyCode;
			if ( chCode == 13 )
				glosario_search();
	}
	
	function getDiccionaryKey(word)
	{
		for (var index in diccionario)
		{
			if (index.indexOf(word) != -1 )
				return index;
		}
		return word;
	}
	
	function glosario_search()
	{
		var word = $('#glosario')[0].value;
		if  (word.length < 3 )
		{
			alert("Especifique al menos 3 letras");
			return;
		}
		var key = getDiccionaryKey(word);
		result = diccionario[key] ;
		if ( ! result )
			result = 'No se han encontrado resultados';
		$('#results_glosario').empty();
		$('#results_glosario').append("<div>"+key+": "+result+"</div>");
	}
	
  </script>
  <script type="text/JavaScript" src="js/jquery-1.7.2.min.js"></script>
  <script type="text/JavaScript" src="js/jquery.easing-1.3.pack.js"></script>
  <script type="text/JavaScript" src="js/jquery.fancybox-1.3.4.js"></script>
  <script type="text/JavaScript" src="js/jquery.mousewheel-3.0.4.pack.js"></script>
  <script type="text/JavaScript" src="js/funcs.js"></script>
  <?php include_once("config.php"); ?>
  
</head>
<body onload="load()">
<div class="top">FANTRAD OpenSource translation projects
<div class="right_opcs">[<a href="perfil.php"><?php print $_SESSION['user'];?></a>]&nbsp;<a href="do_logout.php">Salir</a></div>
</div>
<div class="mid">
<div class="visor_izq">
 <?php if ( isset($_SESSION['doc']) ) { ?>
 <div class="visor_header"><h1><?php print $_SESSION['docname']; ?></h1><div class="menu"><?php include_once("menu.php"); ?></div></div>
 <?php } else { print '</br>'; }?>
 <div class="visor_contenido">
<?php include_once("contenido.php"); ?>
 </div>
 <div class="visor_original">
<?php include_once("contenido_original.php"); ?>
 </div>
</div>
<div class="visor_drc">
<?php include_once("plugins.php"); ?>
</div>
</div>
<div class="bottom">
  Footer
</div>
</body>
 </html>